In [1]:
import matplotlib.pyplot as plt
plt.ion()
from astropy import units as u
from astropy.time import Time
In [2]:
from astropy.utils.data import conf
conf.dataurl
Out[2]:
In [3]:
conf.remote_timeout
Out[3]:
First, we need to increase the timeout time to allow the download of data occur properly
In [4]:
conf.remote_timeout = 10000
Then, we do the rest of the imports and create our initial orbits.
In [5]:
from astropy.coordinates import solar_system_ephemeris
solar_system_ephemeris.set("jpl")
from poliastro.bodies import *
from poliastro.twobody import Orbit
from poliastro.plotting import OrbitPlotter, plot
EPOCH = Time("2017-09-01 12:05:50", scale="tdb")
In [6]:
earth = Orbit.from_body_ephem(Earth, EPOCH)
earth
Out[6]:
In [7]:
plot(earth, label=Earth);
In [8]:
from poliastro.neos import neows
In [9]:
florence = neows.orbit_from_name("Florence")
florence
Out[9]:
Two problems: the epoch is not the one we desire, and the inclination is with respect to the ecliptic!
In [10]:
florence.epoch
Out[10]:
In [11]:
florence.epoch.iso
Out[11]:
In [12]:
florence.inc
Out[12]:
We first propagate:
In [13]:
florence = florence.propagate(EPOCH)
florence.epoch.tdb.iso
Out[13]:
And now we have to convert to the same frame that the planetary ephemerides are using to make consistent comparisons, which is ICRS:
In [14]:
florence_icrs = florence.to_icrs()
florence_icrs.rv()
Out[14]:
Let us compute the distance between Florence and the Earth:
In [15]:
from poliastro.util import norm
In [16]:
norm(florence_icrs.r - earth.r) - Earth.R
Out[16]:
In [17]:
from IPython.display import HTML
HTML(
"""<blockquote class="twitter-tweet" data-lang="en"><p lang="es" dir="ltr">La <a href="https://twitter.com/esa_es">@esa_es</a> ha preparado un resumen del asteroide <a href="https://twitter.com/hashtag/Florence?src=hash">#Florence</a> 😍 <a href="https://t.co/Sk1lb7Kz0j">pic.twitter.com/Sk1lb7Kz0j</a></p>— AeroPython (@AeroPython) <a href="https://twitter.com/AeroPython/status/903197147914543105">August 31, 2017</a></blockquote>
<script src="//platform.twitter.com/widgets.js" charset="utf-8"></script>"""
)
Out[17]:
And now we can plot!
In [18]:
frame = OrbitPlotter()
frame.plot(earth, label="Earth")
frame.plot(Orbit.from_body_ephem(Mars, EPOCH))
frame.plot(Orbit.from_body_ephem(Venus, EPOCH))
frame.plot(Orbit.from_body_ephem(Mercury, EPOCH))
frame.plot(florence_icrs, label="Florence");
The difference between doing it well and doing it wrong is clearly visible:
In [19]:
frame = OrbitPlotter()
frame.plot(earth, label="Earth")
frame.plot(florence, label="Florence (Ecliptic)")
frame.plot(florence_icrs, label="Florence (ICRS)");
And now let's do something more complicated: express our orbit with respect to the Earth! For that, we will use GCRS, with care of setting the correct observation time:
In [20]:
from astropy.coordinates import GCRS, CartesianRepresentation
In [21]:
florence_heclip = florence.frame.realize_frame(
florence.represent_as(CartesianRepresentation)
)
In [22]:
florence_gcrs_trans_cart = (florence_heclip.transform_to(GCRS(obstime=EPOCH))
.represent_as(CartesianRepresentation))
florence_gcrs_trans_cart
Out[22]:
In [23]:
florence_hyper = Orbit.from_vectors(
Earth,
r=florence_gcrs_trans_cart.xyz,
v=florence_gcrs_trans_cart.differentials['s'].d_xyz,
epoch=EPOCH
)
florence_hyper
Out[23]:
We now retrieve the ephemerides of the Moon, which are given directly in GCRS:
In [24]:
moon = Orbit.from_body_ephem(Moon, EPOCH)
moon
Out[24]:
In [25]:
plot(moon, label=Moon)
plt.gcf().autofmt_xdate()
And now for the final plot:
In [26]:
frame = OrbitPlotter()
# This first plot sets the frame
frame.plot(florence_hyper, label="Florence")
# And then we add the Moon
frame.plot(moon, label=Moon)
plt.xlim(-1000000, 8000000)
plt.ylim(-5000000, 5000000)
plt.gcf().autofmt_xdate()